﻿import com.dmotiko.general.*
import com.dmotiko.mirador.*
import mx.transitions.*;
import mx.transitions.easing.*;

class MiradorPhotoGalleryThumb
extends PhotoClip {
	private var initY:Number;
	private var initX:Number;
	private var bActive:Boolean;
	private var mcBack:MovieClip;
	private var mcBig:MovieClip;
	private var mcMini:MovieClip;
		
	private function initClip():Void {
		super.initClip();
		mcMini._visible = false;
		mcBig._visible = false;
		mcImg.enabled = false;
		bActive = false;
			
		this.enabled = false;
	}
	
	private function onLoadInit(target:MovieClip):Void {
		mcBack._x = mcMask._x = mcImg._x = mcMini._x;
		mcBack._y =	mcMask._y = mcImg._y = mcMini._y;
		mcBack._width = mcMask._width = mcImg._width = mcMini._width;
		mcBack._height = mcMask._height = mcImg._height = mcMini._height;
		
		mcImg._alpha = 0;
		if( !bActive) registerTween("imgFade", new Tween(mcImg, "_alpha", Regular.easeOut, mcImg._alpha, 60, 1, true));
		dispatchEvent( { type: BaseClipEvent.READY, target: this } );
	}
	
	private function refreshData():Void {
		var sPath:String = getData().thumb;
		imgLoader.loadClip( sPath, mcImg.img);
	}
	
	public function initThumb():Void {
		this.enabled = true;
	}
	
	public function onRollOver():Void {
		this.swapDepths( this._parent.getNextHighestDepth() - 1 );
		var nDuration:Number = 1.5;
		var fEasing:Function = Elastic.easeOut;
		if(!bActive) registerTween("imgFade", new Tween(mcImg, "_alpha", Regular.easeOut, mcImg._alpha, 100, nDuration, true), false, false, true);
		registerTween("imgScaleX", new Tween( mcImg, "_width", fEasing, mcImg._width, mcBig._width, nDuration, true), false, false, true);
		registerTween("imgScaleY", new Tween( mcImg, "_height", fEasing, mcImg._height, mcBig._height, nDuration, true), false, false, true);
		registerTween("imgX", new Tween( mcImg, "_x", fEasing, mcImg._x, mcBig._x, nDuration, true), false, false, true);
		registerTween("imgY", new Tween( mcImg, "_y", fEasing, mcImg._y, mcBig._y, nDuration, true), false, false, true);
	}
	public function onRollOut():Void {
		var nDuration:Number = 1.5;
		var fEasing:Function = Elastic.easeOut;
		if(!bActive) registerTween("imgFade", new Tween(mcImg, "_alpha", Regular.easeOut, mcImg._alpha, 60, 1, true));
		registerTween("imgScaleX", new Tween( mcImg, "_width", fEasing, mcImg._width, mcMini._width, nDuration, true), false, false, true);
		registerTween("imgScaleY", new Tween( mcImg, "_height", fEasing, mcImg._height, mcMini._height, nDuration, true), false, false, true);
		registerTween("imgX", new Tween( mcImg, "_x", fEasing, mcImg._x, mcMini._x, nDuration, true), false, false, true);
		registerTween("imgY", new Tween( mcImg, "_y", fEasing, mcImg._y, mcMini._y, nDuration, true), false, false, true);
		
	}
	public function onRelease():Void {
		dispatchEvent( { type: BaseClipEvent.CHANGED, target: this, data: this.data } );
	}
	public function stopMotion():Void {
		this._y = getTween("clipY").finish;
		this._x = getTween("clipX").finish;
		removeTween("clipX");
		removeTween("clipY");
	}
	
	private function tweenChanged(key:String, tween:Tween):Void {
		if ( tween.obj == mcImg ) {
			//trace("tween key= " + key + " | prop= " + tween.prop);
			mcMask[tween.prop] = tween.obj[tween.prop];
			mcBack[tween.prop] = tween.obj[tween.prop];
		}
	}
		
	public function setActive(value:Boolean):Void {
		bActive = value;
		if (bActive) registerTween("imgFade", new Tween(mcImg, "_alpha", Regular.easeOut, mcImg._alpha, 100, 1, true));
		else registerTween("imgFade", new Tween(mcImg, "_alpha", Regular.easeOut, mcImg._alpha, 60, 1, true));
	}
	
}